
/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.controller.handleController;

import com.dc.gameserver.proto.gameserverprotoVo.area;
import com.dc.gameserver.proto.gameserverprotoVo.areaRequest;
import com.dc.gameserver.proto.gameserverprotoVo.areaResponse;
import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
import com.dc.gameserver.serverCore.controller.AbstractController.IController;
import com.dc.gameserver.serverCore.model.dbsql.modelCache.ModelCacheService;
import com.dc.gameserver.serverCore.model.dbsql.modelVo.TRoleArea;
import com.dc.gameserver.serverCore.service.character.PlayerInstance;
import com.google.protobuf.MessageLite;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : 石头哥哥
 *         Project : LandlordsServer
 *         Date: 13-6-4
 *         Time: 上午11:49
 *         Connect: 13638363871@163.com
 *         areas信息请求处理
 *         数据库表中记录已经开启（完成）的区域
 */
@Service
@SuppressWarnings("unchecked")
public class areaController extends AbstractController {

    @Resource
    private ModelCacheService modelCacheService;

    /**
     */
    @Override
    public void PostConstruct() {
        int ID= areaRequest.msgID.ID_VALUE;
        GAME_CONTROLLERS[ID]=this;
        IController.MESSAGE_LITE[ID]= areaRequest.getDefaultInstance();
    }

     /**
     * messageLite数据结构体分发
     *
     * @param messageLite
     * @param player
     * @throws Exception
      *
      * 返回玩家区域信息
     */
    @Override
    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
        messageLite=null;
        List<TRoleArea> areasList= (List<TRoleArea>) modelCacheService
                .findListByPrefixID(ModelCacheService.AREA_PREFIX(player.getID()));
        areaResponse.Builder builder=areaResponse.newBuilder();
        if (areasList!=null){
            for (TRoleArea roleArea:areasList){
                area.Builder areaBuilder=area.newBuilder();
                areaBuilder.setAreaID(roleArea.getRoleareaid());
                areaBuilder.setAreaStatus(roleArea.getRoleareastatus());
                areaBuilder.setAllstartsReword(roleArea.getAllstartsreword());//1.未领取，2.已领取，3.未达三星
                builder.addAreaList(areaBuilder.build());
            }
            player.DirectSend(wrappedBufferShort(areaResponse.msgID.ID_VALUE,builder.build()));
        }
    }
}
